#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100009],c[100009],x[5],p[100009],A[100009];
string s[22];
ll ans(int players,int round)
{
    while(1)
    {
        if (players==1)
        if(players==1)return p[1];
        for(int i=1;i<=players;i+=2)
        {
            ll num=(s[round][i/2]-'0');
            if((num==0&&A[i]>=round)||(num==1&&A[i+1]<round))
            {
                A[i/2+1]=A[i];
                p[i/2+1]=p[i];
            }
            else
            {
                A[i/2+1]=A[i+1];
                p[i/2+1]=p[i+1];
            }
        }
        players/=2;
        round+=1;
    }

}
int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    ll n,m,t,answer=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>c[i];
    ll nnn=n,num=0;
    while(nnn>1)
    {
        num++;
        nnn/=2;
    }
    if(pow(2,num)!=n)num++;
    for(int i=1;i<=num;i++)
        cin>>s[i];
    cin>>t>>x[0]>>x[1]>>x[2]>>x[3];
    for(int i=1;i<=n;i++)
    {
        a[i]=(a[i]^(x[i%4]));
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            p[j]=j;
            A[j]=a[j];
        }
        answer=(answer^(i*ans(c[i],1)));
    }
    cout<<answer;
    return 0;
}
